home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / MemInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-22  |  2.3 KB  |  90 lines

  1. /* 
  2.  * MemInit.c --
  3.  *
  4.  *    Source code for "MemInit", a library procedure used internally
  5.  *    by the storage allocator.  Also contains static variables shared
  6.  *    between the allocator routines.  See memInt.h for overall
  7.  *    information about how the allocator works.
  8.  *
  9.  * Copyright 1985, 1988 Regents of the University of California
  10.  * Permission to use, copy, modify, and distribute this
  11.  * software and its documentation for any purpose and without
  12.  * fee is hereby granted, provided that the above copyright
  13.  * notice appear in all copies.  The University of California
  14.  * makes no representations about the suitability of this
  15.  * software for any purpose.  It is provided "as is" without
  16.  * express or implied warranty.
  17.  */
  18.  
  19. #ifndef lint
  20. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/MemInit.c,v 1.1 88/05/20 15:49:17 ouster Exp $ SPRITE (Berkeley)";
  21. #endif not lint
  22.  
  23. #include "memInt.h"
  24.  
  25. /*
  26.  * ----------------------------------------------------------------------------
  27.  *
  28.  * MemInit --
  29.  *
  30.  *      Initializes the dynamic storage allocator.
  31.  *
  32.  * Results:
  33.  *      None.
  34.  *
  35.  * Side effects:
  36.  *      The storage allocation structures are initialized.
  37.  *
  38.  * ----------------------------------------------------------------------------
  39.  */
  40.  
  41. void
  42. MemInit()
  43. {
  44.     int i;
  45.  
  46.     memInitialized = TRUE;
  47.  
  48.     /*
  49.      * Clear out all of the bins.
  50.      */
  51.  
  52.     for (i = 0; i < BIN_BUCKETS; i++) {
  53.     memFreeLists[i] = NOBIN;
  54.     mem_NumBlocks[i] = 0;
  55. #ifdef MEM_TRACE
  56.     mem_NumBinnedAllocs[i] = 0;
  57. #endif
  58.     }
  59.  
  60.     /*
  61.      * Mark all the small buckets except 0 as available for binning.
  62.      * Don't mark 0:  it's used as a special trigger in malloc to
  63.      * return NULL when allocating zero bytes without affecting
  64.      * the inner loop for binned allocations.
  65.      */
  66.  
  67.     for (i = 1; i < SMALL_BUCKETS; i++) {
  68.     memFreeLists[i] = (Address) NULL;
  69.     }
  70.  
  71.     /* 
  72.      * Initialize the large-object free list with two blocks that
  73.      * mark its beginning and end.
  74.      */
  75.  
  76.     memFirst = MemChunkAlloc(MIN_REGION_SIZE);
  77.     memLast = memFirst + MIN_REGION_SIZE - sizeof(AdminInfo);
  78.     SET_ADMIN(memFirst, MARK_FREE(memLast - memFirst));
  79.     SET_ADMIN(memLast, MARK_DUMMY(0));
  80.     memCurrentPtr    = memFirst;
  81.     memLargestFree    = 0;
  82.     memBytesFreed    = 0;
  83.     mem_NumLargeBytes    = MIN_REGION_SIZE;
  84.  
  85. #ifdef MEM_TRACE
  86.     mem_NumLargeAllocs    = 0;
  87.     mem_NumLargeLoops    = 0;
  88. #endif
  89. }
  90.